#!/bin/bash

#config
state=0 #run or not
url="" #smtp服务器
from="" #发件人邮箱
rcpt="" #收件人邮箱
user="" #账号密码，中间用:分割
subject="【快手脚本】运行报告" #主题
value=`cat /root/YMD/run.log` #内容
mail_content_file="/root/YMD/content.txt"
mail_temp_file="/root/YMD/content_temp.txt"

if ((${state} == 1));
then
    echo "From:${from}
To:${rcpt}
Subject: ${subject}

${value} "> ${mail_temp_file}

    iconv -c --verbose -f utf-8 -t gb2312 ${mail_temp_file} -o ${mail_content_file}

    curl -s --url "${url}" --ssl --mail-from "${from}" --mail-rcpt "${rcpt}" --upload-file ${mail_content_file} --user "${user}"

    rm ${mail_content_file} && rm ${mail_temp_file}
fi